from flask import Flask, redirect, url_for

app = Flask(__name__)

@app.route('/')
def home():
    return 'Hello, vscode! - 这是首页'

@app.route('/user/<username>')
def show_user(username):
    return f'Hello, {username}! - 你访问的是用户页面'

@app.route('/submit', methods=['POST'])
def submit():
    return 'Form Submitted - 提交成功'

@app.route('/post/<int:post_id>')
def show_post(post_id):
    return f'Post {post_id} - 你访问的是 ID 为 {post_id} 的页面'

@app.route('/old-page')
def old_page():
    return redirect('/new-page')

@app.route('/new-page')
def new_page():
    return 'This is the new page - 这是一个新的页面'

@app.route('/link')
def link():
    return f'Click to visit user: {url_for("show_user", username="John")}, URL 已自动生成'

if __name__ == '__main__':
    app.run(debug=True)
